package atguigu.jdbc;

import java.sql.*;

public class HiveJdbcClient {

    private static String driverName = "org.apache.hive.jdbc.HiveDriver";  
  
    public static void main(String[] args) throws SQLException {
//        try {
//            Class.forName(driverName);
//        } catch (ClassNotFoundException e) {
//            // 如果找不到驱动，则抛出异常
//            e.printStackTrace();
//            System.exit(1);
//        }
  
        // 连接字符串  10.16.155.240:443
//        String url = "jdbc:hive2://10.23.114.104:10001/";
//        String url = "jdbc:hive2://10.23.114.104:10001/;hive.server2.proxy.user=masr1";

//        lims_bind
//        FfA24s*85M

//        String user = "lims_bind";
//        String password = "FfA24s*85M";
//
//        Connection con = DriverManager.getConnection(url, user, password);

        Connection con = HiveConnectionPool.getConnection();

//        // 创建Statement
        Statement stmt = con.createStatement();
//
//        // 执行查询
        String sql = " SELECT * FROM m_wqyctz_lims.b0_reportdata_04_v2019 LIMIT 10 ";
        System.out.println("Running: " + sql);
        ResultSet res = stmt.executeQuery(sql);
//
        // 处理结果集
        while (res.next()) {
            // 根据你的表结构获取数据
            // 例如：System.out.println(String.valueOf(res.getInt(1)) + "\t" + res.getString(2));
        }

        System.out.println("查询结束");
//
//        // 关闭资源
        res.close();
        stmt.close();
        con.close();  
    }  
}